package com.example.lin.controller;

import com.example.lin.common.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Administrator
 */
@Slf4j
@RestController
@RequestMapping("/test")
public class TestController {
    @GetMapping("/user")
    public R user() {
        Object user = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return R.ok(ObjectUtils.isEmpty(user) ? null : user);
    }
}
